SUBROUTINE utilfun_mayor(pconsin,qconsin,thetain,utilout)

  USE commonvars
  IMPLICIT NONE

  REAL(8), INTENT(IN)  :: pconsin, qconsin, thetain
  REAL(8), INTENT(OUT) :: utilout

  !cobb douglas utility for private and public consumption
!!$  utilout = pconsin**(1-gamma)/(1-gamma)+thetain*(qconsin)**(1-delta)/(1-delta) + upower
!!$  utilout = pconsin**(1-gamma)/(1-gamma)+thetain*(qconsin)**(1-delta)/(1-delta)

  !cobb douglas utility for private consumption and log utility for public consumption
!!$  utilout = pconsin**(1-gamma)/(1-gamma)+thetain*log(qconsin) + upower
!!$  utilout = LOG(pconsin)+thetain*LOG(qconsin) + upower

  ! We add upower in emaxfuntemp and emaxfun, no need to add it here
  IF (ABS(gamma-1d0) < small_no .AND. ABS(delta-1d0) < small_no) THEN
     utilout = LOG(pconsin)+thetain*LOG(qconsin) ! + upower
  ELSE IF (ABS(gamma-1d0) > small_no .AND. ABS(delta-1d0) < small_no) THEN
     utilout = pconsin**(1d0-gamma)/(1d0-gamma)+thetain*LOG(qconsin) ! + upower
!!$     utilout = pconsin**(1-gamma)/(1-gamma)+thetain*qconsin ! + upower
  ELSE IF (ABS(gamma-1d0) < small_no .AND. ABS(delta-1d0) > small_no) THEN
     utilout = LOG(pconsin)+thetain*(qconsin)**(1d0-delta)/(1d0-delta) ! + upower
  ELSE IF (ABS(gamma-1d0) > small_no .AND. ABS(delta-1d0) > small_no) THEN
     utilout = pconsin**(1d0-gamma)/(1d0-gamma)+thetain*(qconsin)**(1d0-delta)/(1d0-delta) ! + upower
  END IF

END SUBROUTINE utilfun_mayor
